home *** CD-ROM | disk | FTP | other *** search
- /* fflush.c */
- #include <stdio.h>
- main()
- {
- int i;
- char line[81];
- FILE *infile;
- /* Open the file. Note that we need two '\' */
- if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
- {
- perror ("fopen failed.\n");
- exit(0);
- }
- /* Now read characters using fgetc */
- for (i=0; i<80; i++)
- {
- line[i] = fgetc(infile);
- if (i==4) fflush(infile); /* Flush buffer */
- if (line[i] == '\n') break;
- }
- line[i+1] = '\0'; /* Mark end of string */
- /* Now print the line and see how it looks */
- printf("The line is: %s", line);
- }